export type Article = {
  art_id: string;
  title: string;
  pubdate: string;
  aut_id: string;
  content: string;
  aut_name: string;
  aut_photo: string;
  is_followed: boolean;
  is_collected: boolean;
  attitude: number;
  comm_count: number;
  like_count: number;
  read_count: number
}



export type CommentListType = {
  total_count: number;
  end_id: string;
  last_id: string;
  results: CommentListItem[]
}

export type CommentListItem = {
  com_id: string;
  content: string;
  reply_count: number;
  pubdate: string;
  is_followed: boolean;
  is_liking: boolean;
  like_count: number;
  aut_id: string;
  aut_name: string;
  aut_photo: string;
}
//定义初始化函数
const initState = {
  info: {} as Article,
  commentList: {} as CommentListType
}
type ArticleType =
  | { type: 'article/getInfo', payload: Article }
  | { type: 'article/setCommentList', payload: CommentListType }
  | { type: 'article/clearCommentList' }


export default function ArticleReducer(state = initState, action: ArticleType) {
  switch (action.type) {
    case 'article/getInfo':
      return { ...state, info: action.payload }
    case 'article/setCommentList':
      return { ...state, commentList: action.payload }
    case 'article/clearCommentList':
      return { ...state, commentList: {} as CommentListType }
    default:
      return state
  }
}